/**
 * Created with JetBrains PhpStorm.
 * User: cgp
 * Date: 13-6-14
 * Time: 上午9:25
 * To change this template use File | Settings | File Templates.
 */
    var pub = {
        ticketState : ['未审核','正常','下架','已拒绝','已删除'],
        ticketOpState : {1:'上架',2:'下架',6:'删除'},
        is_chinese : function(str) {
            var i=0
            for(;i<str.length;i++) {
                if(str.charCodeAt(i)<123) break;
            }
            return i==str.length;
        }
    };

var _chkRequierd = function(chk){
    var countReq = 0, chk=chk||1;
    $("input[type='text']").each(function(key,val){
        if($(this).attr('data-required')==chk && $(this).val().length==0){
            alert($(this).attr('title'));
            $(this).focus();
            countReq += 1;
            return false;
        }
    });
    return countReq;
};
//非法字符过滤BOF
var filterStr = function(){
    var regStr = /[\'\"\,\<\>\+\*\/\%\^\=\\\!\&\|\(\)\[\]\{\}\;\~\`\#\$]+/;
    var val = $(this).val(),str = '';
    if(regStr.test(val)) {
        str = val.replace(regStr,"");
        $(this).val(str);
    }
    return;
};
var tabChg = function(wrap){
    $("a.tab").removeClass('current')
//        $(this).addClass('current');
    //var wrap = wrap;
    $("a.tab[data-wrap='"+wrap+"']").addClass('current');
    $("#"+wrap).show();
    $("#"+wrap).siblings('table').hide();
    $("#"+wrap).siblings('div.ui-box').hide();
    //f.focus();
};
var ckhall = function(elem) {
    var elem = elem || $(this);
    if(elem.attr('checked')) {
        $("input.chk").attr('checked','checked');
    } else {
        $("input.chk").removeAttr('checked');
    }
};
var getChkdIds = function(dataType){
    var ids = '', dataType = dataType || 'string', arr_chkd=[];
    if(dataType=='string') {
        $("input.chk").each(function(k,v){
            $(this).attr('checked')=='checked'? ids += $(this).val()+',':'';

        });
        return ids;
    } else if(dataType=='array') {
        $("input.chk").each(function(k,v){
            $(this).attr('checked')=='checked'? arr_chkd.push($(this).val()):'';
        });
        return arr_chkd;
    }
};
//设置文本框高度
var setHeight = function(obj,opt) {
    var h = 30,elem =obj.siblings('textarea'), sh=elem.height();
    if(opt=='+') {
        elem.height(sh+h);
    } else {
        if(sh<100) return;
        elem.height(sh-h);
    }
};
var chgText = function(pt){
    var arr_route = ['服务标准','行程安排','友情提示','备注'],
        arr_land = ['产品摘要','产品详情','购买须知','交通信息'],
        i = 0;
    if(pt=='A' || pt=='C') {
        $("div.land").show();
        $("div.land").find("input").removeAttr('disabled');
        $("div.land").find("select").removeAttr('disabled');
        for(;i<4;i++)
            $("#route_"+i).text(arr_land[i]);
    } else if(pt=='B'){
        $("div.land").hide();
        $("div.land").find("input").attr('disabled','disabled');
        $("div.land").find("select").attr('disabled','disabled');
        for(;i<4;i++)
            $("#route_"+i).text(arr_route[i]);
    }
};
var showTipMsg = function(obj){
    var pos = obj.offset(), left = pos.left, top = pos.top,msg = obj.attr('data-msg');
    if(!msg.length) return;
    if(!$("#qtmsg").length){
        var elem = "<div id='qtmsg'><div class='qtborder'></div><div class='top'></div><div id='msg' class='center'></div><div class='bot'></div></div>";
        $("body").append(elem);
    }
    $("#msg").text(msg);
    $("#qtmsg").css({left:left-12,top:top+10}).fadeIn('slow');
};
var hideTipMsg = function(){
    $("#qtmsg").fadeOut('slow');
}
if($(".qtmsg").length){
    $('table').on('mouseover','.qtmsg',function(){
        showTipMsg($(this));
    });
    $('table').on('mouseout','.qtmsg',hideTipMsg);
//    $(".qtmsg").bind('mouseover',function(){
//        showTipMsg($(this));
//    });
    //$(".qtmsg").bind('mouseout',hideTipMsg);
}